/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer 55 - I. 二叉树的深度
 * @author: WXY
 * @create: 2022-12-10 20:24
 * @Version 1.0
 **/


public class Num055_1_maxDepth {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        Info ans = process(root);
        return ans.height;
    }

    private Info process(TreeNode root) {
        if (root ==  null) {
            return new Info(0);
        }
        Info leftInfo = process(root.left);
        Info rightInfo = process(root.right);
        int height = Math.max(rightInfo.height ,leftInfo.height) + 1;
        Info curInfo = new Info(height);
        return curInfo;
    }

    public class Info{
        public int height = 0;

        public Info(int height) {
            this.height = height;
        }
    }
}
